package com.sports.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sports.entity.Athletes;
import com.sports.entity.Comment;
import com.sports.entity.CommentDTO;
import com.sports.service.AthletesService;
import com.sports.service.CommentService;
import com.sports.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author LZL
 * @description 针对表【t_comment】的数据库操作Service实现
 * @createDate 2024-03-21 20:55:04
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment>
        implements CommentService {

    @Autowired
    private AthletesService athletesService;
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<CommentDTO> getCommentsByAthletesName(String athletesName) {
        List<Integer> ids = athletesService.list(new LambdaQueryWrapper<Athletes>().like(Athletes::getAthletesName, athletesName)).stream().map(Athletes::getAthletesId).collect(Collectors.toList());
        if (ids.isEmpty()) {
            ids = null;
        }
        return commentMapper.getCommentsAndName(ids);


        // 获取当前名字的 ids, 因为可能会出现重名的
        // List<Integer> ids = athletesService.list(new LambdaQueryWrapper<Athletes>().like(Athletes::getAthletesName, athletesName)).stream().map(Athletes::getAthletesId).collect(Collectors.toList());
        // if (ids.isEmpty()) {
        //     return null;
        // }
        // return list(new LambdaQueryWrapper<Comment>().in(Comment::getUserId, ids));
    }
}




